import request from 'utils/request'

/**
 * 获取文章列表
 * @param {Object} params {}
 * @returns promise
 */
export const getArticles = (params) =>
  request({
    url: '/mp/articles',
    params,
  })

/**
 * 删除文章
 * @param {string} id 文章id
 * @returns promise
 */
export const delArticle = (id) =>
  request({
    method: 'DELETE',
    url: `/mp/articles/${id}`,
  })

/**
 * 添加文章
 * @param {Object} data {}
 * @param {Boolean} draft 是否存为草稿
 * @returns promise
 */
export const addArticle = (data, draft = false) =>
  request({
    method: 'post',
    url: `/mp/articles?draft=${draft}`,
    data,
  })

/**
 * 获取文章详情
 * @param {string} id 文章id
 * @returns promise
 */
export const getArticleById = (id) => request(`/mp/articles/${id}`)

/**
 * 编辑文章
 * @param {Object} data {}
 * @param {Boolean} draft 是否存为草稿
 * @returns promise
 */
export const uploadArticle = (data, draft = false) =>
  request({
    method: 'put',
    url: `/mp/articles/${data.id}?draft=${draft}`,
    data,
  })
